<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Data Visualization Dashboard">
    <meta name="author" content="ACROBOTIC">
    <title>ISS Tracking Dashboard</title>
    <!-- Fonts -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <style>
      .row {
        margin:0 !important;
      }
      html, body {
        border: 0;
        padding: 0;
        margin: 0;
        width: 100%;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <!-- START OF HTML -->
    <div id="map" style="width: 100%; height: 100%"></div>
    <!-- END OF HTML -->
    <script src="//maps.google.com/maps/api/js?libraries=geometry&sensor=false&language=en_us&key={{ api_key }}" type="text/javascript"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="{{ url_for('static', filename='orbit.js') }}" type="text/javascript"></script>
    <script type="text/javascript">
      var map = new google.maps.Map(document.getElementById('map'), {
        zoom: 2,
        center: new google.maps.LatLng(0,0),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        keyboardShortcuts: false,
        streetViewControl: false,
        rotateControl: false,
        panControl: false,
        scaleControl: false,
        zoomControl: false,
        zoomControlOptions: {
          style: google.maps.ZoomControlStyle.DEFAULT
        },
        scrollwheel: false
      });

      var stations;
      var sats = [];

      $.get("stations.txt", function(data) {
        stations = orbits.util.parseTLE(data);
        console.log(stations);

        var i = 0;
        for(;i < stations.length; i++) {
          var name = stations[i].name;
          var satOpts = {
            map: map,
            tle: stations[i],
            pathLength: 1,
          };

          if(name == "ISS (ZARYA)") {
            satOpts.markerOpts = {
              icon: {
                url: "{{ url_for('static', filename='img/iss.png') }}",
                size: new google.maps.Size(65,50),
                scaledSize: new google.maps.Size(65,50),
                anchor: new google.maps.Point(30,30),
              },
            };
          }
          else {
            continue;
          }

          var sat = new orbits.Satellite(satOpts);
          sat.refresh()
          sat.refresh_path();
          sats.push(sat);
        }

        setInterval(function() {
          var i = 0;
          for(;i < sats.length; i++) sats[i].refresh();
        }, 500);

        setInterval(function() {
          var i = 0;
          for(;i < sats.length; i++) sats[i].refresh_path();
        }, 5*60000);
      });
    </script>
  </body>
</html>
